﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SystemDirectory.Entity;
using SystemDirectory.Biz;
using System.Globalization;

namespace SystemDirectory.Pages.Forms
{
    public partial class PremiseEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
            {
                Premise premiseIn = new Premise();
                BOPremise boPremise = new BOPremise();
                premiseIn = boPremise.GetById(Convert.ToInt32(Request.QueryString["id"].ToString()));
                LocationName.Text = premiseIn.locationName;
                KnowAs.Text = premiseIn.knowAs;
                LocationOrganisation.Text = premiseIn.locationOrg;
                LocationStatus.Text = premiseIn.locationOrg;
                statusDate.Text = FormatDate(premiseIn.locationDate);
                addressLine1.Text = premiseIn.address1;
                addressLine2.Text = premiseIn.address2;
                addressLine3.Text = premiseIn.address3;
                postcode.Text = premiseIn.postcode;
                citytown.Text = premiseIn.ctyTown;
                Country.Text = premiseIn.country;
                NationCountry.Text = premiseIn.nationContry;
                primaryLocation.Checked = premiseIn.primary;
                locatinManaged.Checked = premiseIn.locationMa;
                networkConnect.Checked = premiseIn.stNetCon;
                LocationDescription.Text = premiseIn.locatonDes;
                PhoneNumber.Text = premiseIn.phoneNum;
                faxNumber.Text = premiseIn.faxNum;
                miniNumber.Text = premiseIn.minNum;
                isShop.Checked = premiseIn.isShop;
                shopDate.Text = FormatDate(premiseIn.shopDate);
                SpeciallistShop.Checked = premiseIn.specialistDhop;
                isActive.Checked = premiseIn.isActive;
            }
            

        }
        protected String FormatDate(String dateTime)
        {
            String format = "M/d/yyyy hh:mm:ss tt";
            DateTime dt = DateTime.ParseExact(dateTime, format, CultureInfo.InvariantCulture);
            return dt.ToString("M/d/yyyy");
        }
        protected void savePremise_Click(object sender, EventArgs e)
        {
            Page.Validate("vgroup");
            if (Page.IsValid)
            {
                Premise premiseIn = new Premise();
                premiseIn.PremiseId = Convert.ToInt32(Request.QueryString["id"].ToString());
                premiseIn.locationName = LocationName.Text;
                premiseIn.address1 = addressLine1.Text;
                premiseIn.postcode = postcode.Text;
                premiseIn.isActive = isActive.Checked;
                premiseIn.knowAs = KnowAs.Text;
                premiseIn.locationOrg = LocationOrganisation.Text;
                premiseIn.locationStatus = LocationStatus.Text;
                premiseIn.locationDate = statusDate.Text;
                premiseIn.address2 = addressLine2.Text;
                premiseIn.address3 = addressLine3.Text;
                premiseIn.ctyTown = citytown.Text;
                premiseIn.country = Country.Text;
                premiseIn.nationContry = NationCountry.Text;
                premiseIn.primary = primaryLocation.Checked;
                premiseIn.locationMa = locatinManaged.Checked;
                premiseIn.stNetCon = networkConnect.Checked;
                premiseIn.locatonDes = LocationDescription.Text;
                premiseIn.phoneNum = PhoneNumber.Text;
                premiseIn.faxNum = faxNumber.Text;
                premiseIn.minNum = miniNumber.Text;
                premiseIn.isShop = isShop.Checked;
                premiseIn.shopDate = shopDate.Text;
                premiseIn.specialistDhop = SpeciallistShop.Checked;
                premiseIn.mediaContact = mediaContact.Checked;
                premiseIn.mediaContactName = midiaConatcName.Text;
                premiseIn.localDemNote = LocalNotes.Text;
                premiseIn.cateringFac = CateringFac.Checked;
                premiseIn.cateringCon = cateringContact.Text;
                premiseIn.cateringType = CateringType.Text;
                premiseIn.isNet = isNetwok.Text;
                premiseIn.clientItfac = clientIt.Checked;
                premiseIn.clientItDe = clientItFac.Text;
                premiseIn.roomAvai = roomAvaibiaty.Checked;
                premiseIn.volunOpp = volunOpp.Checked;
                premiseIn.travelDatail = travelDetail.Text;
                premiseIn.travelNeaAil = TravelNearestAiport.Text;
                premiseIn.travalNeaRail = TravelNearestRail.Text;
                premiseIn.hostViset = HostVisits.Checked;
                premiseIn.hostContact = HostingContact.Text;
                premiseIn.visitOnsite = VisitorParkingOnsite.Checked;
                premiseIn.visitSpace = VisitorParkingSpaces.Text;
                premiseIn.visitAlte = VisitorParkingAltemative.Text;
                premiseIn.roomRate = RoomOnlyRate.Text;
                premiseIn.bbRate = BBRate.Text;
                premiseIn.dbbRate = DBBRate.Text;
                premiseIn.ddRate = DDRate.Text;
                premiseIn.hrRate = hrRate.Text;
                premiseIn.teaCof = TeaandCoffee.Text;
                premiseIn.luch = Lunch.Checked;
                premiseIn.noRoom = NoofMeetingRooms.Text;
                premiseIn.metRoom = MeetingRoomRate.Text;
                premiseIn.coding = coodding.Text;
                premiseIn.neRoom = NegotiatedRoom.Text;
                premiseIn.bbNeRoom = BBNegotiated.Text;
                premiseIn.dbbNeRoom = DBBNegotiated.Text;
                premiseIn.hrNeRoom = hrNegotiated.Text;
                premiseIn.lastNeRoom = "3/6/2013 12:00:00 AM";// LastNegotiated.Text;
                premiseIn.reNeOn = "3/6/2013 12:00:00 AM"; // RenegotiateOn.Text;
                premiseIn.preStatus = PrefrredStatus.Text;
                premiseIn.commen = Comments.Text;
                BOPremise boPremise = new BOPremise();
                boPremise.UpdatePremise(premiseIn);
                Response.Redirect("/Pages/Views/PremiseList.aspx");
            }
        }
    }
}